home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / objtba.zip / MMGR.DOC < prev    next >
Text File  |  1993-01-04  |  36KB  |  907 lines

  1.    
  2.    
  3.                                            MMGR.PAS LISTING   PAGE  1    
  4.    
  5.    
  6.    PROGRAM MMGR;
  7.    { *******************************************************************
  8.       Author: Thomas W. Harden
  9.       Version: 1.0
  10.    
  11.                         (C) 1990 Thomas W. Harden
  12.                            All rights reserved
  13.    
  14.      Demonstration program for Harden Consulting.  Utilizes Copyrighted
  15.      program developement tools for DataBase manipulation, Menus, and
  16.      Data input/output forms.  A relational data base is used with a
  17.      many to many relationship between the inities (Companies and Persons)
  18.      via a Third file (Contacts).  This is the extent of the programing
  19.      required to implement this application.
  20.    
  21.      ******************************************************************* }
  22.    
  23.    USES Crt,
  24.         Dos,
  25.         OopBase,     { ObjectBase Compiled Unit.              }
  26.         UserIO,      { ObjectInterFace Module                 }
  27.         Windows,     {     "            "                     }
  28.         Forms,       {     "            "                     }
  29.         Fields,      {     "            "                     }
  30.         Utility,     {     "            "                     }
  31.         SysIntro,    { Creates The First Screen Image.        }
  32.         MMgrVar,     { Unit containing Applications variables }
  33.                      {  and initialization routines.          }
  34.         MMgrRpts;    { Unit containing Application specific   }
  35.                      {  report routines.                      }
  36.    
  37.    PROCEDURE InitDB(Var D : DB);
  38.    {
  39.    This procedure is passed the Database variable and calls the the objects
  40.    initialization (D.Init), loads the Datafile information and indexfile
  41.    information, opens the database then sets up the first records to view.
  42.    Note the use of Constants for the FileNames. This makes it easier to
  43.    remember and write the proper term when searching for a file to SwitchTo.
  44.    }
  45.    BEGIN      { InitDB }
  46.      D.Init;
  47.      D.LoadDataFile(New(DFilePtr,init(CompanyData,'',SizeOf(Company),
  48.                      @Company)));
  49.      D.LoadIndexFile(New(IFilePtr,init(CompanySysNdx,'',SizeOf(Company.Code),
  50.                       @Company.Code,0)),CompanyData);
  51.      D.LoadIndexFile(New(IFilePtr,init(CompanyUserNdx,'',SizeOf(Company.Alpha),
  52.                       @Company.Alpha,1)),CompanyData);
  53.      D.LoadDataFile(New(DFilePtr,init(PersonData,'',SizeOf(Person),@Person)));
  54.      D.LoadIndexFile(New(IFilePtr,init(PersonSysNdx,'',SizeOf(Person.Code),
  55.                       @Person.Code,0)),PersonData);
  56.      D.LoadIndexFile(New(IFilePtr,init(PersonUserNdx,'',SizeOf(Person.AlphaK),
  57.                       @Person.AlphaK,1)),PersonData);
  58.      D.LoadDataFile(New(DFilePtr,init(ContactData,'',SizeOf(Contact),@Contact)));
  59.      D.LoadIndexFile(New(IFilePtr,init(ContactCompAccess,'',
  60.                       SizeOf(Contact.Ckey),
  61.                       @Contact.ckey,0)),ContactData);    
  62.    
  63.                                            MMGR.PAS LISTING   PAGE  2    
  64.    
  65.    
  66.      D.LoadIndexFile(New(IFilePtr,init(ContactPrsnAccess,'',
  67.                       SizeOf(Contact.PKey),
  68.                       @Contact.PKey,0)),ContactData);
  69.      D.Open;
  70.      D.SwitchTo(CompanyData);    { Sets 'COMPANY.DAT' to primary file  }
  71.      D.SetIndex(CompanyUserNdx); { Sets 'COMPALPH.NDX' as ordering Ndx }
  72.      D.Top;                      { Sets Company to the 1st alphabetic  }
  73.                                  {  entry in file                      }
  74.      D.SwitchTo(PersonData);     { Sets 'PERSON.DAT' to primary file   }
  75.      D.SetIndex(PersonUserNdx);  { Sets 'PRSNALPH.NDX' as ordering Ndx }
  76.      D.Top;                      { Sets Person to the 1st alphabetic   }
  77.                                  {  entry  in file                     }
  78.    END;       { InitDB }
  79.    
  80.    
  81.    PROCEDURE CompanyMaint;
  82.    VAR
  83.      Choice,
  84.      Choice1 : Integer;          { Menu selection variables }
  85.      Finished,
  86.      Finished1 : Boolean;        { Loop Control variables   }
  87.      Key : String;
  88.      Ch  : Char;                 { Dummy receiver for pause }
  89.    
  90.    BEGIN
  91.    { Set up relations for viewing data from company perspective }
  92.    { Company  --> Contact --> Person                            }
  93.    {    code  <--         --> code                              }
  94.      DBase.LoadRelation( CompanyData,ContactData,ContactCompAccess,
  95.                          @Company.Code);
  96.      DBase.loadRelation( ContactData,PersonData,PersonSysNdx,
  97.                          @Contact.personCode);
  98.      Choice := 0;
  99.      Finished := False;
  100.      PushHelp(ord(CompanyHelp));     { Sets context sinsitive help system}
  101.      DBase.Switchto(CompanyData);
  102.      DBase.SetIndex(CompanyUserNdx);
  103.      DBase.get;
  104.      DBase.Associate(CompanyData);   { Sets Record variables to values based }
  105.                                      { on the Relations just loaded          }
  106.      CompForm.Show;                  { This an instance of the Form object   }
  107.      REPEAT
  108.        CompForm.Leave;               { Informs CompForm that it is inactive, }
  109.                                      {  Still visible.                       }
  110.        Choice := CompanyMenu.Pop;    { Displays PopUp Menu and Returns Choice}
  111.        CompanyMenu.Hide;             { Removes Menu From Screen              }
  112.        Case Choice of
  113.          1: BEGIN  { Record Edit }
  114.               PushHelp(ord(CompanyeditHelp));  { Sets help to Edit Help }
  115.               if Not DBase.Empty then
  116.               begin
  117.                 compform.edit;
  118.                 company.rcst.upstamp := timeStamp;
  119.                 dbase.put;
  120.               end
  121.               else    
  122.    
  123.                                            MMGR.PAS LISTING   PAGE  3    
  124.    
  125.    
  126.                 with EmptyFileMsg do     { <-- EmptyFileMsg is a Message }
  127.                 begin                    {     object.                   }
  128.                   show;
  129.                   Ch := ReadKey;
  130.                   hide;
  131.                 end;
  132.               PopHelp;                    { Returns help to prevs state }
  133.             END;  { Record Edit }
  134.          2: BEGIN { Find Record }
  135.               if Not DBase.Empty then
  136.               begin
  137.                 PushHelp(ord(CompanyFindHelp));
  138.                 Key := query('Enter Alpha Key of Company desired?',
  139.                              Rpt('U',SizeOf(company.alpha)-1),
  140.                              SizeOf(company.alpha)-1);
  141.                 DBase.Search(Key);
  142.                 DBase.Associate(CompanyData);
  143.                 CompForm.show;
  144.                 popHelp;
  145.               end
  146.               else
  147.                 with EmptyFileMsg do
  148.                 begin
  149.                   show;
  150.                   Ch := ReadKey;
  151.                   hide;
  152.                 end;
  153.             END;  { Find Record }
  154.          3: BEGIN { Get Next Record }
  155.               if Not DBase.Empty then
  156.               begin
  157.                 dbase.next;                    { Returns the next record in }
  158.                                                { the primary file, orderd by}
  159.                                                { the active index.          }
  160.                 DBase.Associate(CompanyData);  { Aligns Dbase based on the  }
  161.                                                { the active relations       }
  162.                 compform.show;
  163.               end
  164.               else
  165.                 with EmptyFileMsg do
  166.                 begin
  167.                   show;
  168.                   Ch := ReadKey;
  169.                   hide;
  170.                 end;
  171.             END;
  172.          4: BEGIN
  173.               if Not DBase.Empty then
  174.               begin
  175.                 dbase.Prev;                    { Returns the Prevs record in }
  176.                                                { the primary file, orderd by }
  177.                                                { the active index.           }
  178.                 DBase.Associate(CompanyData);  { Aligns Dbase based on the   }
  179.                                                { the active relations        }
  180.                 compform.show;
  181.               end    
  182.    
  183.                                            MMGR.PAS LISTING   PAGE  4    
  184.    
  185.    
  186.               else
  187.                 with EmptyFileMsg do
  188.                 begin
  189.                   show;
  190.                   Ch := ReadKey;
  191.                   hide;
  192.                 end;
  193.             END;   { get Previous record }
  194.          5: BEGIN  { Add a Company record }
  195.               PushHelp(ord(CompanyaddHelp));
  196.               dbase.blankrecord;        { Initializes the Pimary Data Record }
  197.               DBase.Associate(CompanyData);
  198.               company.rcst.instamp := timeStamp;
  199.               company.code := nextcode(dbase.lastcode(companysysndx),
  200.                                         sizeof(company.code)-1);
  201.               compform.edit;            { CompForm object will edit itself }
  202.               compform.leave;
  203.               company.rcst.upstamp := timeStamp;
  204.               if YesNo(concat('Do really want to add this record to ',
  205.                       CompanyData,'?')) Then
  206.                  dbase.add                    { yes add record to file }
  207.               ELSE
  208.               BEGIN                           { No reset file to prev state }
  209.                 DBase.prev;
  210.                 DBAse.Associate(CompanyData);
  211.                 CompForm.show;                { show reset data }
  212.               END;
  213.               PopHelp;
  214.             END;  { Add Record }
  215.          6: BEGIN { Set Flag Field }
  216.               if Not DBase.Empty then
  217.               begin
  218.                 Company.Flag := Not (Company.flag);
  219.                 DBase.put;
  220.                 CompForm.show;
  221.               end
  222.               else
  223.                 with EmptyFileMsg do
  224.                 begin
  225.                   show;
  226.                   Ch := ReadKey;
  227.                   hide;
  228.                 end;
  229.             END;
  230.          7: BEGIN  { Add a Contact }
  231.               if Not DBase.Empty then
  232.               begin
  233.                 PushHelp(ord(companycontacthelp));
  234.                 DBase.Switchto(PersonData);
  235.                 DBase.SetIndex(PersonUserNdx);
  236.               { Get Person Key }
  237.                 Key := '';
  238.                 Key := Query('Enter last name of Contact->',
  239.                              rpt('U',sizeof(person.LName)-2),
  240.                              sizeof(Person.LName)-2);
  241.               { Show located person record }    
  242.    
  243.                                            MMGR.PAS LISTING   PAGE  5    
  244.    
  245.    
  246.                 DBase.Search(Key);
  247.                 PrsnContForm.Show;
  248.               { Get correct person record }
  249.                 Finished1 := False;
  250.                 REPEAT
  251.                   PrsnContForm.Leave;
  252.                   Choice1 := CompContMenu.Pop;
  253.                   CompContMenu.Hide;
  254.                   Case Choice1 of
  255.                     1 : BEGIN                         { Correct    }
  256.                           if Not DBase.Empty then
  257.                           begin
  258.                             pushHelp(ord(Comp2PrsnAddHelp));
  259.                             DBase.SwitchTo(ContactData);
  260.                             DBAse.BlankRecord;
  261.                             Contact.Position := Query(
  262.                                Concat('Enter ',Person.FName,' ',Person.LName,
  263.                                '''s position with ',Company.alpha,'->'),
  264.                                rpt('W',sizeof(contact.Position)-1),
  265.                                sizeof(Contact.Position)-1);
  266.                             Contact.PersonCode := Person.Code;
  267.                             Contact.CompanyCode := Company.Code;
  268.                             Contact.PKey := Concat(Contact.PersonCode,
  269.                                                    Contact.CompanyCode);
  270.                             Contact.CKey := Concat(Contact.CompanyCode,
  271.                                                    Contact.PersonCode);
  272.                             dbase.setindex(ContactCompAccess);
  273.                             if DBase.keyexist(contact.cKey) then
  274.                             begin
  275.                               RecordExists.show;
  276.                               ch := Readkey;
  277.                               RecordExists.hide;
  278.                             end
  279.                             else
  280.                             DBase.add;
  281.                             Finished1 := True;
  282.                             PopHelp;
  283.                           end
  284.                           else
  285.                             with EmptyFileMsg do
  286.                             begin
  287.                               show;
  288.                               Ch := ReadKey;
  289.                               hide;
  290.                             end;
  291.                         END;
  292.                     2 : BEGIN                         { Next       }
  293.                           if Not DBase.Empty then
  294.                           begin
  295.                             DBase.Next;
  296.                             PrsnContForm.show;
  297.                           end
  298.                           else
  299.                             with EmptyFileMsg do
  300.                             begin
  301.                               show;    
  302.    
  303.                                            MMGR.PAS LISTING   PAGE  6    
  304.    
  305.    
  306.                               Ch := ReadKey;
  307.                               hide;
  308.                             end;
  309.                         END;
  310.                     3 : BEGIN                         { Prev       }
  311.                           if Not DBase.Empty then
  312.                           begin
  313.                             DBase.Prev;
  314.                             PrsnContForm.Show;
  315.                           end
  316.                           else
  317.                             with EmptyFileMsg do
  318.                             begin
  319.                               show;
  320.                               Ch := ReadKey;
  321.                               hide;
  322.                             end;
  323.                         END;
  324.                     4 : BEGIN                         { Add Person }
  325.                           PushHelp(ord(PersonAddHelp));
  326.                           dbase.blankrecord;
  327.                           dbase.Switchto(contactdata);
  328.                           dbase.blankrecord;
  329.                           dbase.switchto(persondata);
  330.                           Person.rcst.instamp := timeStamp;
  331.                           Person.code := nextcode(dbase.lastcode(Personsysndx),
  332.                                          sizeof(Person.code)-1);
  333.                           PersonForm.edit;
  334.                           Person.rcst.upstamp := timeStamp;
  335.                           Person.AlphaK := UpcaseStr(concat(copy(Person.LName,1,
  336.                                            sizeof(person.AlphaK)-2),
  337.                                            copy(person.fname,1,1)));
  338.                           personform.leave;
  339.                           if YesNo(concat('Do really want to add this record to ',
  340.                                   PersonData,'?')) Then
  341.                              dbase.add
  342.                           ELSE
  343.                             DBAse.Associate(companyData);
  344.                           PersonForm.Hide;
  345.                           prsnContform.show;
  346.                           popHelp;
  347.                         END;
  348.                     5 : Finished1 := True;           { Abandon    }
  349.                   END;
  350.                 UNTIL Finished1;
  351.                 PrsnContForm.hide;
  352.                 Dbase.SwitchTo(CompanyData);
  353.                 DBase.SetIndex(CompanyUserNdx);
  354.                 CompForm.Show;
  355.                 PopHelp;
  356.               end
  357.               else
  358.                 with EmptyFileMsg do
  359.                 begin
  360.                   show;
  361.                   Ch := ReadKey;    
  362.    
  363.                                            MMGR.PAS LISTING   PAGE  7    
  364.    
  365.    
  366.                   hide;
  367.                 end;
  368.             END;
  369.          8: BEGIN                          { View Next Contact }
  370.               if Not DBase.Empty then
  371.               begin
  372.                 DBase.NextAssoc(CompanyData);
  373.                 CompForm.Show;
  374.               end
  375.               else
  376.                 with EmptyFileMsg do
  377.                 begin
  378.                   show;
  379.                   Ch := ReadKey;
  380.                   hide;
  381.                 end;
  382.             END;
  383.          9: BEGIN  { Delete a Contact relationship }
  384.               if Not DBase.Empty then
  385.               begin
  386.                 Finished1 := False;
  387.                 REPEAT
  388.                   PushHelp(ord(contactDel));
  389.                 { present menu of choices }
  390.                   Choice1 := PersonContDelMenu.pop;
  391.                   PersonContDelMenu.Hide;
  392.                   Case Choice1 of
  393.                     1 : BEGIN     { Delete this one }
  394.                           Dbase.Switchto(ContactData);
  395.                           DBase.DelRec;
  396.                           Dbase.SwitchTo(CompanyData);
  397.                           Dbase.Associate(CompanyData);
  398.                           CompForm.Show;
  399.                           Finished1 := True;
  400.                         END;
  401.                     2 : BEGIN     { Get Next Relation }
  402.                           DBase.Nextassoc(PersonData);
  403.                           CompForm.Show;
  404.                         END;
  405.                     3 : BEGIN     { Abort }
  406.                           finished1 := True;
  407.                         END;
  408.                   END;
  409.                   Compform.leave;
  410.                 UNTIL finished1;
  411.                 PopHelp;
  412.               end
  413.               else
  414.                 with EmptyFileMsg do
  415.                 begin
  416.                   show;
  417.                   Ch := ReadKey;
  418.                   hide;
  419.                 end;
  420.             END;
  421.         10: Finished := True;    
  422.    
  423.                                            MMGR.PAS LISTING   PAGE  8    
  424.    
  425.    
  426.        END;
  427.      UNTIL Finished;
  428.      CompForm.Hide;
  429.      DBase.ClearRelations;           { Removes set of relations loaded for }
  430.                                      { this application.                   }
  431.                                      { At this time there are no known     }
  432.                                      { relations                           }
  433.      PopHelp;
  434.    END;
  435.    
  436.    PROCEDURE PersonMaint;
  437.    VAR
  438.      Choice,
  439.      Choice1 : Integer;
  440.      Finished,
  441.      Finished1 : Boolean;
  442.      Key : String;
  443.      Ch  : Char;
  444.    
  445.    BEGIN
  446.      Choice := 0;
  447.      Finished := False;
  448.      pushhelp(ord(personhelp));
  449.    { Set up relations for this section of code.                     }
  450.    { Person --> Contact --> Company                                 }
  451.    {   Code <--/       \--> Code                                    }
  452.      DBase.LoadRelation( PersonData,ContactData,ContactPrsnAccess,
  453.                          @Person.Code);
  454.      DBase.loadRelation( ContactData,CompanyData,CompanySysNdx,
  455.                          @Contact.CompanyCode);
  456.      DBase.Switchto(PersonData);
  457.      DBase.SetIndex(PersonUserNdx);
  458.      dbase.get;
  459.      DBase.Associate(PersonData);
  460.      PersonForm.Show;
  461.      REPEAT
  462.        PersonForm.Leave;
  463.        Choice := PersonMenu.Pop;
  464.        PersonMenu.Hide;
  465.        Case Choice of
  466.          1: BEGIN
  467.               if Not DBase.Empty then
  468.               begin
  469.                 pushhelp(ord(PersonEdithelp));
  470.                 PersonForm.edit;
  471.                 Person.rcst.upstamp := timeStamp;
  472.                 Person.AlphaK := UpcaseStr(concat(copy(Person.LName,1,
  473.                                      sizeof(person.AlphaK)-2),
  474.                                      copy(person.fname,1,1)));
  475.                 dbase.Put;
  476.                 pophelp;
  477.               end
  478.               else
  479.                 with EmptyFileMsg do
  480.                 begin
  481.                   show;    
  482.    
  483.                                            MMGR.PAS LISTING   PAGE  9    
  484.    
  485.    
  486.                   Ch := ReadKey;
  487.                   hide;
  488.                 end;
  489.             END;
  490.          2: BEGIN
  491.               if Not DBase.Empty then
  492.               begin
  493.                 pushhelp(ord(Personfindhelp));
  494.                 Key := query('Enter Last Name of Individual desired?',
  495.                              rpt('U',sizeof(Person.LName)-2),
  496.                              sizeof(Person.LName)-2);
  497.                 DBase.Search(Key);
  498.                 DBase.Associate(PersonData);
  499.                 PersonForm.show;
  500.                 pophelp;
  501.               end
  502.               else
  503.                 with EmptyFileMsg do
  504.                 begin
  505.                   show;
  506.                   Ch := ReadKey;
  507.                   hide;
  508.                 end;
  509.             END;
  510.          3: BEGIN
  511.               if Not DBase.Empty then
  512.               begin
  513.                 dbase.next;                    { Returns the Next record in  }
  514.                                                { the primary file, orderd by }
  515.                                                { the active index.           }
  516.                 DBase.Associate(PersonData);   { Aligns Dbase based on the   }
  517.                                                { the active relations        }
  518.                 PersonForm.show;
  519.               end
  520.               else
  521.                 with EmptyFileMsg do
  522.                 begin
  523.                   show;
  524.                   Ch := ReadKey;
  525.                   hide;
  526.                 end;
  527.             END;
  528.          4: BEGIN
  529.               if Not DBase.Empty then
  530.               begin
  531.                 dbase.Prev;                    { Returns the Prevs record in }
  532.                                                { the primary file, orderd by }
  533.                                                { the active index.           }
  534.                 DBase.Associate(PersonData);   { Aligns Dbase based on the   }
  535.                                                { the active relations        }
  536.                 PersonForm.show;
  537.               end
  538.               else
  539.                 with EmptyFileMsg do
  540.                 begin
  541.                   show;    
  542.    
  543.                                            MMGR.PAS LISTING   PAGE  10   
  544.    
  545.    
  546.                   Ch := ReadKey;
  547.                   hide;
  548.                 end;
  549.             END;
  550.          5: BEGIN
  551.               PushHelp(ord(PersonAddHelp));
  552.               dbase.blankrecord;
  553.               DBase.associate(PersonData);
  554.               Person.rcst.instamp := timeStamp;
  555.               Person.code := nextcode(dbase.lastcode(Personsysndx),
  556.                              sizeof(Person.code)-1);
  557.               PersonForm.edit;
  558.               PersonForm.Leave;
  559.               Person.rcst.upstamp := timeStamp;
  560.               Person.AlphaK := UpcaseStr(concat(copy(Person.LName,1,
  561.                                sizeof(person.AlphaK)-2),
  562.                                copy(person.fname,1,1)));
  563.               if YesNo(concat('Do really want to add this record to ',
  564.                       PersonData,'?')) Then
  565.                  dbase.add
  566.               ELSE
  567.               BEGIN
  568.                 DBase.get;
  569.                 DBAse.Associate(PersonData);
  570.                 PersonForm.show;
  571.               END;
  572.               PopHelp;
  573.             END;
  574.          6: BEGIN
  575.               if Not DBase.Empty then
  576.               begin
  577.                 Person.Flag := Not (Person.Flag);
  578.                 Dbase.put;
  579.                 PersonForm.show;
  580.               end
  581.               else
  582.                 with EmptyFileMsg do
  583.                 begin
  584.                   show;
  585.                   Ch := ReadKey;
  586.                   hide;
  587.                 end;
  588.             END;
  589.          7: BEGIN
  590.               if Not DBase.Empty then
  591.               begin
  592.                 PushHelp(Ord(PersonContactHelp));
  593.                 DBase.Switchto(companyData);
  594.                 DBase.SetIndex(companyUserNdx);
  595.                 { Get company Key }
  596.                 Key := '';
  597.                 Key := Query('Enter Company AlphaKey->',
  598.                        rpt('U',sizeof(Company.alpha)-1),
  599.                        sizeof(company.alpha)-1);
  600.                 { Show located company record }
  601.                 DBase.Search(Key);    
  602.    
  603.                                            MMGR.PAS LISTING   PAGE  11   
  604.    
  605.    
  606.                 CompContForm.Show;
  607.                 { Get correct company record }
  608.                 Finished1 := False;
  609.                 REPEAT
  610.                   CompContForm.Leave;
  611.                   Choice1 := PrsnContMenu.Pop;
  612.                   PrsnContMenu.Hide;
  613.                   Case Choice1 of
  614.                     1 : BEGIN                         { Correct    }
  615.                           if Not DBase.Empty then
  616.                           begin
  617.                             PushHelp(Ord(Prsn2CompAddHelp));
  618.                             DBase.SwitchTo(ContactData);
  619.                             DBAse.BlankRecord;
  620.                             Contact.Position := Query(
  621.                                Concat('Enter ',Person.FName,' ',Person.LName,
  622.                                '''s position with ',Company.Alpha,'->'),
  623.                                rpt('W',sizeof(contact.Position)-1),
  624.                                sizeof(Contact.Position)-1);
  625.                             Contact.PersonCode := Person.Code;
  626.                             Contact.CompanyCode := Company.Code;
  627.                             Contact.PKey := Concat(Contact.PersonCode,
  628.                                                    Contact.CompanyCode);
  629.                             Contact.CKey := Concat(Contact.CompanyCode,
  630.                                                    Contact.PersonCode);
  631.                             dbase.setindex(ContactPrsnAccess);
  632.                             if DBase.keyexist(contact.PKey) then
  633.                             begin
  634.                               RecordExists.show;
  635.                               ch := Readkey;
  636.                               RecordExists.hide;
  637.                             end
  638.                             else
  639.                               DBase.Add;
  640.                             Finished1 := True;
  641.                             popHelp;
  642.                           end
  643.                           else
  644.                             with EmptyFileMsg do
  645.                             begin
  646.                               show;
  647.                               Ch := ReadKey;
  648.                               hide;
  649.                             end;
  650.                         END;
  651.                     2 : BEGIN                         { Next       }
  652.                           if Not DBase.Empty then
  653.                           begin
  654.                             DBase.Next;
  655.                             CompContForm.show;
  656.                           end
  657.                           else
  658.                             with EmptyFileMsg do
  659.                             begin
  660.                               show;
  661.                               Ch := ReadKey;    
  662.    
  663.                                            MMGR.PAS LISTING   PAGE  12   
  664.    
  665.    
  666.                               hide;
  667.                             end;
  668.                         END;
  669.                     3 : BEGIN                         { Prev       }
  670.                           if Not DBase.Empty then
  671.                           begin
  672.                             DBase.Prev;
  673.                             CompContForm.Show;
  674.                           end
  675.                           else
  676.                             with EmptyFileMsg do
  677.                             begin
  678.                               show;
  679.                               Ch := ReadKey;
  680.                               hide;
  681.                             end;
  682.                         END;
  683.                     4 : BEGIN                         { Add company }
  684.                           PushHelp(ord(CompanyAddhelp));
  685.                           dbase.blankrecord;
  686.                           dbase.Switchto(contactdata);
  687.                           dbase.blankrecord;
  688.                           dbase.switchto(companydata);
  689.                           company.rcst.instamp := timeStamp;
  690.                           company.code := nextcode(dbase.lastcode(companysysndx),
  691.                                          sizeof(company.code)-1);
  692.                           compForm.edit;
  693.                           company.rcst.upstamp := timeStamp;
  694.                           Compform.leave;
  695.                           if YesNo(concat('Do really want to add this record to ',
  696.                                 CompanyData,'?')) Then
  697.                             dbase.add
  698.                           ELSE
  699.                             DBAse.Associate(PersonData);
  700.                           CompForm.Hide;
  701.                           CompContform.show;
  702.                           popHelp;
  703.                         END;
  704.                     5 : Finished1 := True;           { Abandon    }
  705.                   END;
  706.                 UNTIL Finished1;
  707.                 CompContForm.hide;
  708.                 Dbase.SwitchTo(CompanyData);
  709.                 DBase.SetIndex(CompanyUserNdx);
  710.                 PersonForm.Show;
  711.                 PopHelp;
  712.               end
  713.               else
  714.                 with EmptyFileMsg do
  715.                 begin
  716.                   show;
  717.                   Ch := ReadKey;
  718.                   hide;
  719.                 end;
  720.             END;
  721.          8: BEGIN    
  722.    
  723.                                            MMGR.PAS LISTING   PAGE  13   
  724.    
  725.    
  726.               if Not DBase.Empty then
  727.               begin
  728.                 DBase.NextAssoc(PersonData);
  729.                 PersonForm.Show;
  730.               end
  731.               else
  732.                 with EmptyFileMsg do
  733.                 begin
  734.                   show;
  735.                   Ch := ReadKey;
  736.                   hide;
  737.                 end;
  738.             END;
  739.          9: BEGIN
  740.               if Not DBase.Empty then
  741.               begin
  742.                 Finished1 := False;
  743.                 REPEAT
  744.                   { present menu of choices }
  745.                   Choice1 := PersonContDelMenu.pop;
  746.                   PersonContDelMenu.Hide;
  747.                   Case Choice1 of
  748.                     1 : BEGIN     { Delete this one }
  749.                           Dbase.Switchto(ContactData);
  750.                           DBase.DelRec;
  751.                           Dbase.SwitchTo(PersonData);
  752.                           Dbase.Associate(PersonData);
  753.                           PersonForm.Show;
  754.                           Finished1 := True;
  755.                         END;
  756.                     2 : BEGIN     { Get Next Relation }
  757.                           DBase.Nextassoc(PersonData);
  758.                           PersonForm.Show;
  759.                         END;
  760.                     3 : BEGIN     { Abort }
  761.                          finished1 := True;
  762.                         END;
  763.                   END;
  764.                   Personform.leave;
  765.                 UNTIL finished1;
  766.               end
  767.               else
  768.                 with EmptyFileMsg do
  769.                 begin
  770.                   show;
  771.                   Ch := ReadKey;
  772.                   hide;
  773.                 end;
  774.             END;
  775.         10: Finished := True;
  776.        END;
  777.      UNTIL Finished;
  778.      PersonForm.Hide;
  779.      DBase.ClearRelations;           { Removes set of relations loaded for }
  780.                                      { this application.                   }
  781.                                      { At this time there are no known     }    
  782.    
  783.                                            MMGR.PAS LISTING   PAGE  14   
  784.    
  785.    
  786.                                      { relations                           }
  787.      popHelp;
  788.    END;
  789.    
  790.    Procedure reports;
  791.    { Calls routines found in MMGRRPTS.PAS }
  792.    
  793.    var
  794.      choice : integer;
  795.      Finished : Boolean;
  796.    
  797.    begin
  798.      pushhelp(ord(reporthelp));
  799.      Finished := False;
  800.      Repeat
  801.        Choice := ReportMenu.Pop;
  802.        ReportMenu.Leave;
  803.        CASE Choice of
  804.          1 : MailLabels;
  805.          2 : CompanyReports;
  806.          3 : ContactReports;
  807.          4 : Finished := True;
  808.        End;
  809.      Until Finished;
  810.      ReportMenu.Hide;
  811.      pophelp;
  812.    end;
  813.    
  814.    Procedure Utilities;
  815.    var Choice : integer;
  816.        Finished : boolean;
  817.        DBSaveMsg: message;
  818.    begin
  819.      PushHelp(ord(UtilHelp));
  820.      Finished := False;
  821.      Repeat
  822.        choice := utilMenu.pop;
  823.        UtilMenu.leave;
  824.        case choice of
  825.          1 : Begin
  826.                PushHelp(ord(ColorHelp));
  827.                Set_Colors;                { ObjectInterFace - User can set }
  828.                                           { colors to any value he wants   }
  829.                PopHelp;
  830.              end;
  831.          2 : Begin
  832.                DbSaveMsg.init(
  833.                  'Saving Data and Index files to disk. Please be Patient.');
  834.                Dbsavemsg.show;
  835.                DBase.Save;
  836.                dbsavemsg.done;
  837.              end;
  838.          3 : finished := true;
  839.        end
  840.      Until finished;
  841.      UtilMenu.hide;    
  842.    
  843.                                            MMGR.PAS LISTING   PAGE  15   
  844.    
  845.    
  846.      PopHelp;
  847.    end;
  848.    
  849.    {$F+}
  850.    PROCEDURE MyExitProc;
  851.    { This is done to insure that the data files are closed should a }
  852.    { problem occur and program is prematurly terminated.            }
  853.    BEGIN      { MyExitProc }
  854.      ExitProc := SysExit;
  855.      dbclosemsg.show;
  856.      DBase.Close;
  857.      dbclosemsg.hide;
  858.      textmode(OldMode);
  859.      DBase.Done;
  860.    END;       { MyExitProc }
  861.    {$F-}
  862.    
  863.    BEGIN  { Main }
  864.    { Set up for Exit Code }
  865.      SysExit := ExitProc;
  866.      ExitProc:= @MyExitProc;
  867.    { Save current video mode }
  868.      OldMode := LastMode;
  869.    
  870.      InitHelp(HelpFileName);  { Part of the ObjectInterFace }
  871.      PushHelp(Ord(OverView));
  872.      InitMsgs;
  873.      Introduction;
  874.      dbloadMsg.show;  { Message object method (ObjectInterFace) - displays }
  875.                       { Text passed when object was initialized.           }
  876.      dbloadmsg.leave; { Message Object method (ObjectInterFace) - DeActivates }
  877.                       { the Message window but leaves it visible. (Lets    }
  878.                       { program address other portions of the screen.)     }
  879.      Initdb(DBase);   { Loads Data and Index Files into Dbase, opens files,}
  880.                       { and sets record variables to first alphabetic record}
  881.      InitMenus;       { Defines the Menus used in program MMGRVARS.PAS      }
  882.      InitForms;       { Defines the Forms used in program MMGRVARS.PAS      }
  883.      dbloadmsg.hide;  { Message object method (ObjectInterFace) - Restores  }
  884.                       { Screen to state previous to show call.              }
  885.      Finished := False;
  886.      REPEAT
  887.        Pushhelp(Ord(MMhelp));{ Sets helpdata to MainMenu date(ObjectInterFace)}
  888.        choice := MainMenu.pop;{ Shows and returns user selection from MainMenu}
  889.                               { Menu Object(ObjectInterface)                  }
  890.        mainmenu.hide;         { Removes Menu from screen.                     }
  891.        case choice of
  892.          1 : CompanyMaint;
  893.          2 : PersonMaint;
  894.          3 : Reports;
  895.          4 : Utilities;
  896.          5 : Finished := YesNo('Do you really want to leave program?');
  897.        END;
  898.      UNTIL Finished;
  899.      PopHelp;
  900.    { Remember exit code will execute at this time or any time the program is }
  901.    { terminated.                                                             }    
  902.    
  903.                                            MMGR.PAS LISTING   PAGE  16   
  904.    
  905.    
  906.    END.   { program }
  907.